import pygame
import time
from hang import *
import sys
import os
pygame.mixer.init(44100)
pygame.display.set_mode((320, 200))
def szamkimond(szam):
	param=sys.argv[0]
	konyvtar=os.path.dirname(param)
	if (konyvtar !=""):
		konyvtar =konyvtar+"/locale/hu/numbers"
	else:
		konyvtar ="locale/hu/numbers"
	szamok_2 =['10.ogg', 'tizen.ogg', 'huszon.ogg', 'harminc.ogg', 'negyven.ogg', 'otven.ogg', 'hatvan.ogg', 'hetven.ogg', 'nyolcvan.ogg', 'kilencven.ogg']
	meret =len(str(szam))
	szams =str(szam)
	szamhang =[]
	x =meret
	for i in range(meret):
		if (x ==4):
			if (int(szams[meret-4]) ==1):
				ezer =konyvtar+'/1000.ogg'
				szamhang.append(ezer)
				x =x-1
			else:
				ezres =konyvtar+'/'+szams[meret-4]+".ogg"
				szamhang.append(ezres)
				ezer =konyvtar+'/1000.ogg'
				szamhang.append(ezer)
				x =x-1
		if (x ==3):
			if (int(szams[meret-3]) >1 or meret >3):
				szazas =konyvtar+'/'+szams[meret-3]+".ogg"
				szamhang.append(szazas)
				szaz =konyvtar+'/100.ogg'
				szamhang.append(szaz)
				x =x-1
			#if (int(szams[meret-3]) ==1):
			else:
				szazas =konyvtar+'/100.ogg'
				szamhang.append(szazas)
				x =x-1
		if (x ==2):
			if (int(szams[meret-2]) ==1 and int(szams[meret-1]) ==0):
				tizes =konyvtar+'/10.ogg'
				szamhang.append(tizes)
			if (int(szams[meret-2]) ==2 and int(szams[meret-1]) ==0):
				tizes =konyvtar+'/20.ogg'
				szamhang.append(tizes)
			if (int(szams[meret-1]) >0):
				tizes =konyvtar+'/'+szamok_2[int(szams[meret-2])]
				szamhang.append(tizes)
			if (int(szams[meret-1]) ==0):
				x =0
			else:
				x =x-1
		if (x==1):
			if (int(szams[meret-1]) >0):
				egyes =konyvtar+'/'+szams[meret-1]+".ogg"
				szamhang.append(egyes)
				x =x-1
	i =0
	for i in range(len(szamhang)):
		if (i ==0):
			hang =pygame.mixer.Sound(szamhang[i])
			csat =hang.play()
		if (i >0 and i<len(szamhang)+1):
			csat.queue(pygame.mixer.Sound(szamhang[i]))
			while (csat.get_busy()):
				for esemeny in pygame.event.get():
					if esemeny.type == pygame.KEYDOWN:
						csat.stop()
						i =len(szamhang)+1
	time.sleep(1)
	return 1

def tellnumber(number):
	param=sys.argv[0]
	directory=os.path.dirname(param)
	if (directory !=""):
		directory =directory+"/locale/en/numbers"
	else:
		directory ="locale/en/numbers"
	numbers_2 =['', '', '20.ogg', '30.ogg', '40.ogg', '50.ogg', '60.ogg', '70.ogg', '80.ogg', '90.ogg']
	size =len(str(number))
	numbers =str(number)
	soundofnumber =[]
	x =size
	for i in range(size):
		if (x ==4):
			thousants =directory+'/'+numbers[size-4]+".ogg"
			soundofnumber.append(thousants)
			thousant=directory+'/1000.ogg'
			soundofnumber.append(thousant)
			x =x-1
		if (x ==3):
			hundreds =directory+'/'+numbers[size-3]+".ogg"
			soundofnumber.append(hundreds)
			hundred=directory+'/100.ogg'
			soundofnumber.append(hundred)
			x =x-1
		if (x ==2):
			if (int(numbers[size-2])>1):
				decimal =directory+'/'+numbers_2[int(numbers[size-2])]
				soundofnumber.append(decimal)
				x =x-1
			if (int(numbers[size-2])==1):
				odd =directory+'/'+numbers[size-2]+numbers[size-1]+".ogg"
				soundofnumber.append(odd)
				x =0
		if (x ==1):
			if (int(numbers[size-1]) >0):
				odd =directory+'/'+numbers[size-1]+".ogg"
				soundofnumber.append(odd)
				x =x-1
	for i in range(len(soundofnumber)):
		if (i ==0):
			hang =pygame.mixer.Sound(soundofnumber[i])
			csat =hang.play()
		if (i >0 and i<len(soundofnumber)+1):
			csat.queue(pygame.mixer.Sound(soundofnumber[i]))
			while (csat.get_busy()):
				for esemeny in pygame.event.get():
					if esemeny.type == pygame.KEYDOWN:
						csat.stop()
						i =len(soundofnumber)+1
	time.sleep(1)
	return 1
